package mlz.a_string;

//String的常用方法
public class StringAPIDemo02 {
    public static void main(String[] args) {
        //创建字符串对象
        String s = "你好Java";

        //1.获取字符串长度
        int length = s.length();
        System.out.println(length);//6

        //2.获取字符串中某个索引位置上的字符
        char c = s.charAt(1);// 索引位置:0 - s.length-1
        System.out.println(c);
        System.out.println("-------------------------------");
        //挨个获取字符串中的字符
        for (int i = 0; i < s.length(); i++) {
            System.out.println(s.charAt(i));
        }
        System.out.println("-------------------------------");

        //3.把字符串转换成字符数组,遍历数组,输出全部内容
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }
        System.out.println("-------------------------------");


        //4.判断字符串内容是否相等
        String s1 = new String("你好");
        String s2 = new String("你好");
        //判断的地址值是否相等
        System.out.println(s1 == s2);//false
        //判断内容是否相等
        System.out.println(s1.equals(s2));//true
        System.out.println("-------------------------------");

        //5.判断字符串内容是否相等,但是忽略大小写
        String s3 = "Za";
        String s4 = "zA";
        System.out.println(s3.equals(s4));//false
        boolean b = s3.equalsIgnoreCase(s4);//true
        System.out.println(b);
        System.out.println("-------------------------------");

    }
}














